<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property string $name 等级名称
 * @property string $self_consume 自消费
 * @property integer $recommend_level 推荐等级
 * @property integer $recommend_count 直推个数
 * @property string $group_consume 团队总消费
 * @property integer $group_consume_include_self 团队总消费(是否含自己)
 * @property integer $love 爱心个数
 * @property float $recommend_rate 消费直推奖励比例
 * @property float $indirect_recommend_rate 消费间推奖励比例
 * @property string $invite_recommend_amount 申请名片直推奖
 * @property string $invite_indirect_recommend_amount 申请名片间推奖
 */
class UserLevel extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_user_levels';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    public static function list()
    {
        $data = self::all()->toArray();

        $newData = [];

        foreach ($data as $key=>$value) {
            $newData[] = ['name' => $value['name'], 'value' => $value['id']];
        }

        return $newData;
    }

    public static function getLevelMap()
    {
        $data = self::list();

        return array_combine(
            array_column($data, 'value'),
            array_column($data, 'name')
        );
    }

    public static function getLevelText($level)
    {
        $levelInfo = self::where('id', $level)->first();

        return $levelInfo['name'];
    }
}
